import Vue from 'vue'
import VueRouter from 'vue-router'
import DeskHome from '../views/desk/Home.vue'
// import nProgress from "nprogress"

Vue.use(VueRouter)
// 解决报错
// const originalPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }

const routes = [{
    path: "/",
    redirect: "/home/article_list"
  },
  {
    path: '/home',
    name: 'DeskHome',
    component: DeskHome,
    redirect: "/home/article_list",
    children: [{
        path: "article_list",
        name: 'ArticleList',
        component: () => import( /* webpackChunkName:"article_list" */ '../views/desk/home/article_list/ArticleList.vue')
      },
      {
        path: "pigeonhole",
        name: 'Pigeonhole',
        component: () => import( /* webpackChunkName:"pigeonhole" */ '../views/desk/home/Pigeonhole.vue')
      },
      {
        path: "projects",
        name: 'Projects',
        component: () => import( /* webpackChunkName:"projects" */ '../views/desk/home/Projects.vue')
      },
      {
        path: "gallery",
        name: 'Gallery',
        component: () => import( /* webpackChunkName:"gallery" */ '../views/desk/home/Gallery.vue')
      },
      {
        path: "leave_message",
        name: 'LeaveMessage',
        component: () => import( /* webpackChunkName:"leave_message" */ '../views/desk/home/LeaveMessage.vue')
      },
      {
        path: "friend_link",
        name: 'FriendLink',
        component: () => import( /* webpackChunkName:"friend_link" */ '../views/desk/home/FriendLink.vue')
      },
      {
        path: "about",
        name: 'About',
        component: () => import( /* webpackChunkName:"about" */ '../views/desk/home/About.vue')
      },{
        path: "article_info",
        name:"ArticleInfo",
        component: ()=> import( /*webpackChunkName:"article_info" */ '../views/desk/home/article_list/ArticleInfo.vue')
      }
    ]
  },
  {
    path: "/admin/login",
    name: "Login",
    component: () => import( /*webpackChunkName:"login" */ '../views/admin/Login.vue')
  },
  {
    path:"/admin",
    name:"Admin",
    redirect:"/admin/dashboard/home",
    meta:{
      title:"主页 / "
    },
    component:()=>import(/*webpackChunkName:"dashboard" */"../views/admin/Home.vue"),
    children:[
      {
        path:"dashboard/home",
        name:"Home",
        meta:{
          title:"仪表盘 / 首页"
        },
        component:()=>import(/*webpackChunkName:'home' */ "../views/admin/dashboard/Dashboard.vue")  
      },
      {
        path:"article_manager/all_article",
        name:"AllArticle",
        meta:{
          title:"文章管理 / 全部文章"
        },
        component:()=>import(/*webpackChunkName:"all_article" */"../views/admin/article_manager/AllArticle.vue")
      },
      {
        path:"article_manager/edit_article/:id",
        name:"EditArticle",
        meta:{
          title:"文章管理 / 编辑文章"
        },
        component:()=>import(/*webpackChunkName:"edit_article" */"../views/admin/article_manager/EditArticle.vue")
      },
      {
        path:"article_manager/types",
        name:"Types",
        meta:{
          title:"文章管理 / 类别"
        },
        component:()=>import(/*webpackChunkName:"types" */"../views/admin/article_manager/ArticleTypes.vue")
      },
      {
        path:"article_manager/labels",
        name:"Labels",
        meta:{
          title:"文章管理 / 标签"
        },
        component:()=>import(/*webpackChunkName:"labels" */"../views/admin/article_manager/ArticleLabels.vue")
      }
    ]
  },
  {
    path: "*",
    name: "Page404",
    component: () => import( /* webpackChunkName:"page404"*/ '../views/other/Page404.vue')
  }
]

const router = new VueRouter({
  mode: 'hash',
  routes
})

// 页面刚开始切换的时候
// router.beforeEach((to, from, next) => {
//     // 开启进度条
//     nProgress.start()
//     next()
// })

// 页面切换完毕的时候
// router.afterEach( () => {
//    // 关闭进度条
//    nProgress.done()
// })

export default router